package com.demo.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.Date;

@Slf4j
@EnableBinding({MyMessageChannel.class})
public class SmsProducer {
    @Resource
    private MyMessageChannel myMessageChannel;

    public String sendDelayedMessage(String body,Integer seconds) {
        myMessageChannel.out().send(
                MessageBuilder.withPayload(body)
                        .setHeader("x-delay", seconds * 1000)
                        .build()
        );
        log.info("开始时间{}，消息发送成功：{}",new Date(),body);
        return "SUCCESS";
    }

}
